#ifndef MANAGEMENTWIDGET_H
#define MANAGEMENTWIDGET_H

#include <QWidget>
#include <QDebug>
#include <QListWidgetItem>
#include <QMessageBox>
#include "userdata.h"
#include "adduserdialog.h"
#include "userdata.h"
#include "addprivilegedialog.h"

namespace Ui {
    class ManagementWidget;
}

class ManagementWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ManagementWidget(QWidget *parent = 0);
    ~ManagementWidget();

    void setOwner(const QString&);
    void loadUserList(UserData *);

signals:
    //void loadUser
    void loadUsers(UserData *);
    void loadAccessList(UserData *); //*
    void addNewUser(UserData *); //*
    void removeUser(UserData *); //*
    void addAccessRight(const QString &, const QString &);
    void removeAccessRight(const QString &, const QString &);

    void disconnectUserListSignal(); //GUI internal use
    void sendAllUserListToPrivilegeAddDialog(QListWidget *);

public slots:
    void userList(QStringList *);
    void userListError(const QString &);
    void accessList(QStringList *);
    void accessListError(const QString &);
    void addNewUserSuccess(const QString &); //username  *
    void addNewUserFailed(const QString &);             // *
    void removeUserSuccess();        //*
    void removeUserFailed(const QString &);  //*
    void addAccessRightSuccess();
    void addAccessRightFailed(const QString &);
    void removeAccessRightSuccess();        //*
    void removeAccessRightFailed(const QString &);  //*

    void receiveSelectedAccessRightFromDialog(const QString &); // GUI internal use
    void receiveNewUserInfoFromDialog(const QString &, const QString &, int); //GUI internal use

private slots:
    void on_userList_itemClicked(QListWidgetItem *item);
    void on_addUserButton_clicked();
    void on_removeUserButton_clicked();
    void on_addAccessRightButton_clicked();
    void on_removeAccessRightButton_clicked();

    void on_privilegeList_itemClicked(QListWidgetItem *item);

private:
    void disableAllWidgets();
    void enableAllWidets();
    Ui::ManagementWidget *ui;
    QString owner;
    QString newAccess;
};

#endif // MANAGEMENTWIDGET_H
